package cn.tedu.charging.device.startup;

import cn.tedu.charging.device.dao.repository.ChargingStationCacheRepository;
import cn.tedu.charging.device.dao.repository.ChargingStationRepository;
import cn.tedu.charging.device.pojo.po.ChargingStationPO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class StationDataInit implements ApplicationRunner {
    @Autowired
    private ChargingStationRepository stationRepository;
    @Autowired
    @Qualifier("GEOANDNoShareHash")
    private ChargingStationCacheRepository chargingStationCacheRepository;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.debug("服务启动时从数据库查询场站信息存储到Redis");
        List<ChargingStationPO> stationPOS =  stationRepository.getStations();
        log.debug("从数据库查询到的场站信息:{}",stationPOS);
        log.debug("将场站数据存储到Redis");
        chargingStationCacheRepository.saveStations2Redis(stationPOS);
        log.debug("存储到Redis成功");
    }
}
